package symbol;

import java.util.ArrayList;
import java.util.List;

import irnode.IRNode;
import xyz.SimpleNode;

public class ClassDecl extends Symbol {

	private ClassDecl parent;
	private FieldEnv fields;
	private MethodEnv methods;
	
	private List<String> fieldNames = new ArrayList<String>();

	public ClassDecl(Env p, String name, SimpleNode node) {
		super(p, name, node);
		fields = new FieldEnv(this, "fields", null);
		methods = new MethodEnv(this, "methods", null);
		parent = null;
	}

	public void setFields(FieldEnv fields) {
		this.fields = fields;
	}

	public FieldEnv getFields() {
		return fields;
	}

	public void setMethods(MethodEnv methods) {
		this.methods = methods;
	}

	public MethodEnv getMethods() {
		return methods;
	}

	public String toString() {
		return "ClassDecl:" + getName() + "\n";
	}

	public void dump() {
		System.out.print(toString());
		fields.dump();
		methods.dump();
	}

	public void setParent(ClassDecl parent) {
		this.parent = parent;
	}

	public ClassDecl getParent() {
		return parent;
	}

	public MethodDecl getThatMethod(String methodName, IRNode expList) {
		return methods.getThatMethod(methodName, expList);
	}
	
	public void insertFieldName(String fieldName){
		fieldNames.add(fieldName);
	}
	
	public List<String> getFieldNamesBefore(String fieldName){
		List<String> result = new ArrayList<String>();
		for (String str : fieldNames) {
			if (str.equals(fieldName)){
				break;
			}
			else{
				result.add(str);
			}
		}
		return result;
	}
}
